import { writeFile } from 'fs/promises'
import path from 'path'
import consola from 'consola'
import pkg from '../packages/components/package.json' assert {type: 'json'} // need to be checked
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);


export const projRoot = path.resolve(__dirname, '..')
export const epRoot = path.resolve(projRoot, 'packages/components/src')
console.log('%c [ epRoot ]-18', 'font-size:13px; background:#6f4163; color:#b385a7;', epRoot)
function getVersion() {
    const tagVer = process.env.TAG_VERSION
    if (tagVer) {
      return tagVer.startsWith('v') ? tagVer.slice(1) : tagVer
    } else {
      return pkg.version
    }
  }
  
  const version = getVersion()

  async function main () {
    consola.info(`Version: ${version}`)
    await writeFile( path.resolve(epRoot, 'version.ts'),  `export const version = '${version}'\n`)
  }
  main()